package j.framework.qmd.core;

import java.io.Serializable;

/**
 * User: jason
 * Date: 14-9-4 上午11:13
 */
public class DataColumn implements Serializable {

    private boolean usedFieldNameAsKey;

    public DataColumn(){}

    public DataColumn(boolean usedFieldNameAsKey,String dataColumnId,String tableAliasName, String columnName){
        this.usedFieldNameAsKey = usedFieldNameAsKey;
        this.dataColumnId = dataColumnId;
        this.tableAliasName = tableAliasName;
        this.columnName = columnName;
    }

    public String getFieldKey(){
        if(usedFieldNameAsKey){
            return columnName;
        }else{
            return dataColumnId;
        }
    }

    private String dataColumnId;

    private String tableAliasName;

    private String columnName;//对应的数据库表中的名称

    public String getDataColumnId() {
        return dataColumnId;
    }
    public void setDataColumnId(String dataColumnId) {
        this.dataColumnId = dataColumnId;
    }

    public String getTableAliasName() {
        return tableAliasName;
    }
    public void setTableAliasName(String tableAliasName) {
        this.tableAliasName = tableAliasName;
    }

    public String getColumnName() {
        return columnName;
    }
    public void setColumnName(String columnName) {
        this.columnName = columnName;
    }

    public boolean isUsedFieldNameAsKey() {
        return usedFieldNameAsKey;
    }
    public void setUsedFieldNameAsKey(boolean usedFieldNameAsKey) {
        this.usedFieldNameAsKey = usedFieldNameAsKey;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        DataColumn that = (DataColumn) o;

        if (columnName != null ? !columnName.equals(that.columnName) : that.columnName != null) return false;
        if (tableAliasName != null ? !tableAliasName.equals(that.tableAliasName) : that.tableAliasName != null)
            return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = tableAliasName != null ? tableAliasName.hashCode() : 0;
        result = 31 * result + (columnName != null ? columnName.hashCode() : 0);
        return result;
    }
}
